{{ header }}
<div id="product-search" class="container">
  <ul class="breadcrumb">
    {% for breadcrumb in breadcrumbs %}
      <li class="breadcrumb-item"><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
    {% endfor %}
  </ul>
  <div class="row">{{ column_left }}
    <div id="content" class="col">
      {{ content_top }}
      <h1>{{ heading_title }}</h1>
      <label class="col-form-label" for="input-search">{{ entry_search }}</label>
      <div class="row">
        <div class="col-md-4">
          <input type="text" name="search" value="{{ search }}" placeholder="{{ text_keyword }}" id="input-search" class="form-control"/>
        </div>
        <div class="col-md-3">
          <select name="category_id" class="form-control">
            <option value="0">{{ text_category }}</option>
            {% for category_1 in categories %}
              {% if category_1.category_id == category_id %}
                <option value="{{ category_1.category_id }}" selected="selected">{{ category_1.name }}</option>
              {% else %}
                <option value="{{ category_1.category_id }}">{{ category_1.name }}</option>
              {% endif %}
              {% for category_2 in category_1.children %}
                {% if category_2.category_id == category_id %}
                  <option value="{{ category_2.category_id }}" selected="selected">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ category_2.name }}</option>
                {% else %}
                  <option value="{{ category_2.category_id }}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ category_2.name }}</option>
                {% endif %}
                {% for category_3 in category_2.children %}
                  {% if category_3.category_id == category_id %}
                    <option value="{{ category_3.category_id }}" selected="selected">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ category_3.name }}</option>
                  {% else %}
                    <option value="{{ category_3.category_id }}">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{ category_3.name }}</option>
                  {% endif %}
                {% endfor %}
              {% endfor %}
            {% endfor %}
          </select>
        </div>
        <div class="col-md-3">
          <div class="form-check form-check-inline">
            <div class="form-check-input">
              {% if sub_category %}
                <input type="checkbox" name="sub_category" value="1" id="input-sub-category" class="form-check-input" checked="checked"/>
              {% else %}
                <input type="checkbox" name="sub_category" value="1" id="input-sub-category" class="form-check-input"/>
              {% endif %}
            </div>
            <label class="form-check-label" for="input-sub-category">{{ text_sub_category }}</label>
          </div>
        </div>
      </div>
      <div class="form-check mb-3">
        {% if description %}
          <input type="checkbox" name="description" value="1" id="input-description" class="form-check-input" checked="checked"/>
        {% else %}
          <input type="checkbox" name="description" value="1" id="input-description" class="form-check-input"/>
        {% endif %}
        <label class="form-check-label" for="input-description">{{ entry_description }}</label>
      </div>
      <button type="button" id="button-search" class="btn btn-primary">{{ button_search }}</button>
      <hr/>
      <h2>{{ text_search }}</h2>
      {% if products %}
        <div id="display-control" class="row">
          <div class="col-md-3">
            <div class="mb-3">
              <a href="{{ compare }}" id="compare-total" class="btn btn-primary d-block"><i class="fas fa-exchange-alt"></i> <span class="d-inline d-md-none d-lg-inline">{{ text_compare }}</span></a>
            </div>
          </div>
          <div class="col-md-1 d-none d-md-block">
            <div class="btn-group">
              <button type="button" id="list-view" class="btn btn-light" data-toggle="tooltip" title="{{ button_list }}"><i class="fas fa-th-list"></i></button>
              <button type="button" id="grid-view" class="btn btn-light" data-toggle="tooltip" title="{{ button_grid }}"><i class="fas fa-th"></i></button>
            </div>
          </div>
          <div class="col-md-4 offset-md-1 col-6">
            <div class="input-group mb-3">
              <div class="input-group-prepend">
                <label class="input-group-text" for="input-sort">{{ text_sort }}</label>
              </div>
              <select id="input-sort" class="form-control" onchange="location = this.value;">
                {% for sorts in sorts %}
                  {% if sorts.value == '%s-%s'|format(sort, order) %}
                    <option value="{{ sorts.href }}" selected="selected">{{ sorts.text }}</option>
                  {% else %}
                    <option value="{{ sorts.href }}">{{ sorts.text }}</option>
                  {% endif %}
                {% endfor %}
              </select>
            </div>
          </div>
          <div class="col-md-3 col-6">
            <div class="input-group mb-3">
              <div class="input-group-prepend">
                <label class="input-group-text" for="input-limit">{{ text_limit }}</label>
              </div>
              <select id="input-limit" class="form-control" onchange="location = this.value;">
                {% for limits in limits %}
                  {% if limits.value == limit %}
                    <option value="{{ limits.href }}" selected="selected">{{ limits.text }}</option>
                  {% else %}
                    <option value="{{ limits.href }}">{{ limits.text }}</option>
                  {% endif %}
                {% endfor %}
              </select>
            </div>
          </div>
        </div>
        <div class="row">
          {% for product in products %}
            <div class="product-layout product-list col-12">
              <div class="product-thumb">
                <div class="image"><a href="{{ product.href }}"><img src="{{ product.thumb }}" alt="{{ product.name }}" title="{{ product.name }}" class="img-fluid"/></a></div>
                <div>
                  <div class="caption">
                    <h4><a href="{{ product.href }}">{{ product.name }}</a></h4>
                    <p>{{ product.description }}</p>
                    {% if product.price %}
                      <p class="price">
                        {% if  not product.special %}
                          {{ product.price }}
                        {% else %}
                          <span class="price-new">{{ product.special }}</span> <span class="price-old">{{ product.price }}</span>
                        {% endif %}
                        {% if product.tax %}
                          <span class="price-tax">{{ text_tax }} {{ product.tax }}</span>
                        {% endif %}
                      </p>
                    {% endif %}
                    {% if product.rating %}
                      <div class="rating">
                        {% for i in 1..5 %}
                          {% if product.rating < i %}
                            <span class="fas fa-stack"><i class="fas fa-star-o fa-stack-2x"></i></span>
                          {% else %}
                            <span class="fas fa-stack"><i class="fas fa-star fa-stack-2x"></i><i class="fas fa-star-o fa-stack-2x"></i></span>
                          {% endif %}
                        {% endfor %}
                      </div>
                    {% endif %}
                  </div>
                  <div class="button-group">
                    <button type="button" onclick="cart.add('{{ product.product_id }}', '{{ product.minimum }}');"><i class="fas fa-shopping-cart"></i> <span class="d-none d-lg-inline">{{ button_cart }}</span></button>
                    <button type="button" data-toggle="tooltip" title="{{ button_wishlist }}" onclick="wishlist.add('{{ product.product_id }}');"><i class="fas fa-heart"></i></button>
                    <button type="button" data-toggle="tooltip" title="{{ button_compare }}" onclick="compare.add('{{ product.product_id }}');"><i class="fas fa-exchange-alt"></i></button>
                  </div>
                </div>
              </div>
            </div>
          {% endfor %}
        </div>
        <div class="row">
          <div class="col-sm-6 text-left">{{ pagination }}</div>
          <div class="col-sm-6 text-right">{{ results }}</div>
        </div>
      {% else %}
        <p>{{ text_no_results }}</p>
      {% endif %}
      {{ content_bottom }}
    </div>
    {{ column_right }}
  </div>
</div>
<script type="text/javascript"><!--
$('#button-search').bind('click', function() {
	url = 'index.php?route=product/search';

	var search = $('#content input[name=\'search\']').prop('value');

	if (search) {
		url += '&search=' + encodeURIComponent(search);
	}

	var category_id = $('#content select[name=\'category_id\']').prop('value');

	if (category_id > 0) {
		url += '&category_id=' + encodeURIComponent(category_id);
	}

	var sub_category = $('#content input[name=\'sub_category\']:checked').prop('value');

	if (sub_category) {
		url += '&sub_category=true';
	}

	var filter_description = $('#content input[name=\'description\']:checked').prop('value');

	if (filter_description) {
		url += '&description=true';
	}

	location = url;
});

$('#content input[name=\'search\']').bind('keydown', function(e) {
	if (e.keyCode == 13) {
		$('#button-search').trigger('click');
	}
});

$('select[name=\'category_id\']').on('change', function() {
	if (this.value == '0') {
		$('input[name=\'sub_category\']').prop('disabled', true);
	} else {
		$('input[name=\'sub_category\']').prop('disabled', false);
	}
});

$('select[name=\'category_id\']').trigger('change');
--></script>
{{ footer }}
